// pages/agent/commission/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    commissionList:[],
    siteId: app.globalData.cityCode,
    projectName:'',
    cityList:[
      { name: "全部", id: '' },
      { name: "合肥", id: 340100},
      { name: "芜湖", id: 340200 },
      { name: "蚌埠", id: 340300 },
      { name: "阜阳", id: 341200 },
      { name: "安庆", id: 340800 },
      { name: "淮南", id: 340400 },
      { name: "淮北", id: 340600 },
      { name: "铜陵", id: 340700 },
      { name: "六安", id: 341500 },
      { name: "巢湖", id: 340181},
      { name: "池州", id: 341700 },
      { name: "亳州", id: 341600 },
      { name: "徐州", id: 320300 },
      { name: "杜丹江", id: 231000 },
      { name: "宿州", id: 341300 },
      { name: "商丘", id: 411400 },
      { name: "宣城", id: 341800 },
      { name: "滁州", id: 341100 },
    ],
    index:0
  },

  /**
   * 获取佣金楼盘
   */
  getLoupanList(){
    var siteId      = this.data.siteId;
    var projectName = this.data.projectName;
    app.core('get', 'agentCashNewhouse?siteId=' + siteId, {projectName:projectName}, (res) => {
      console.log(res)
      this.setData({
        commissionList: res.data
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let siteId = app.globalData.cityCode

    var cityList = this.data.cityList
    for (var i = 0; i < cityList.length ; i++ ){
      if (siteId == cityList[i].id ){
          this.setData({index:i})
      }
    }
    this.setData({siteId:siteId})
    this.getLoupanList();

  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

/**
 * 搜索词汇
 */
  searchlist(e){
    var projectName = e.detail.value;
    this.setData({projectName:projectName});
  },

/**
 * 搜索按钮
 */
  searchdesc(){
    this.getLoupanList();
  },

 /**
  * 切换城市
  */
  onPickerChange(e){
    var index = e.detail.value;
    this.setData({index:index})
    var siteId = this.data.cityList[index].id;

    this.setData({siteId:siteId})
    console.log(siteId,678)
    this.getLoupanList(); 
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})